﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Krypton;
using Krypton.Lights;

namespace ConstantCMapEditor3
{
    class LightSourceScene : Scene
    {
        private Light2D PointLightSource;

        public void ChangeLightTexture(Texture2D lightTexture2D)
        {

        }

        public LightSourceScene()
        {
            PointLightSource = new Light2D();

            PointLightSource.Texture = Game1.mLightTexture;
            PointLightSource.Range = (float)(1);
            PointLightSource.Color = new Color(255, 255, 255);
            PointLightSource.Intensity = 1.0f;
            PointLightSource.X = (float)(0);
            PointLightSource.Y = (float)(0);
        }

        public int Shadow
        {
            get
            {
                return PointLightSource.ShadowFilter;
            }
            set
            {
                PointLightSource.ShadowFilter = value;
            }
        }

        public float Intensity
        {
            get 
            {
                return PointLightSource.Intensity;
            }
            set 
            {
                PointLightSource.Intensity = value;
            }
        }

        virtual public float Width
        {
            get;
            set;
        }

        virtual public float Height
        {
            get;
            set;
        }

        private int _lightType = 0;

        public int LightType
        {
            get
            {
                return _lightType;
            }

            set
            {
                if (value < 0) value += 4;
                _lightType = value % 4;

                if (_lightType == 0)
                {
                    PointLightSource.Texture = Game1.mLightTexture;
                }
                else if (_lightType == 1)
                {
                    PointLightSource.Texture = Game1.mLightConicTexturehalf;

                }
                else if (_lightType == 2)
                {
                    PointLightSource.Texture = Game1.mLightConicTexture1;

                }
                else if (_lightType == 3)
                {
                    PointLightSource.Texture = Game1.mLightConicTexture2;
                }
            }
        }

        override protected void AbsoluteDraw(SpriteBatch batch, Vector2 position, float rotate, float scaleX, float scaleY, Color color)
        {

            float width = Width * _absoluteScaleX;

            PointLightSource.Color = SpriteColor;
            PointLightSource.Position = new Vector2(_absolutePosition.X - 1366 / 2, -_absolutePosition.Y + 768 / 2);
            PointLightSource.Range = width;
            PointLightSource.Angle = -_absoluteRotate;


            Game1.krypton.Lights.Add(PointLightSource);
        }

    }



    class LightBlocker : Scene
    {
        private ShadowHull sh;

        public enum BlockShape
        {
            Rectangle,
            Circle,
        }

        public LightBlocker()
        {
            sh = ShadowHull.CreateRectangle(new Vector2(1, 1));
            sh.Position = new Vector2(0, 0);

            Game1.krypton.Hulls.Add(sh);

        }

        public int ShadowType
        {
            get
            {
                return sh.ShadowType;
            }

            set
            {
                sh.ShadowType = value;
            }
        }

        public LightBlocker(BlockShape shape)
        {
            if (shape == BlockShape.Circle)
            {
                sh = ShadowHull.CreateCircle(1, 16);
            }
            else
            {
                sh = ShadowHull.CreateRectangle(new Vector2(1, 1));
            }
            sh.Position = new Vector2(0, 0);

        

        }

  
        virtual public float Width
        {
            get;
            set;
        }

        virtual public float Height
        {
            get;
            set;
        }

        override protected void AbsoluteDraw(SpriteBatch batch, Vector2 position, float rotate, float scaleX, float scaleY, Color color)
        {
            float width = Width * _absoluteScaleX;
            float height = Height * _absoluteScaleY;

            sh.Position = new Vector2(_absolutePosition.X - 1366 / 2, -_absolutePosition.Y + 768 / 2);
            sh.Scale = new Vector2(width, height);
            sh.Angle = -_absoluteRotate;

            Game1.krypton.Hulls.Add(sh);
        }

    }
}
